<%
# Copyright (C) 2011 - present Instructure, Inc.
#
# This file is part of Canvas.
#
# Canvas is free software: you can redistribute it and/or modify it under
# the terms of the GNU Affero General Public License as published by the Free
# Software Foundation, version 3 of the License.
#
# Canvas is distributed in the hope that it will be useful, but WITHOUT ANY
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
# A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
# details.
#
# You should have received a copy of the GNU Affero General Public License along
# with this program. If not, see <http://www.gnu.org/licenses/>.
%>

<% content_for :page_title do %><%= t(:submissions_upload, "%{assignment} Submissions Upload", :assignment => @assignment.title) %>: <%= t(:comments_made, {:one => "1 Comment Made", :other => "%{count} Comments Made"}, :count => @comments.length) %>, <%= t(:files_ignored, {:one => "1 File Ignored", :other => "%{count} Files Ignored"}, :count => @failures.length) %><% end %>

<% content_for :right_side do %>
  <p><%= t(:done, <<-TEXT)
    Done! We took the files you uploaded and attached them with a short comment
    to each user's submission page for this assignment. The students will get a
    notification that a new comment was added.
    TEXT
  %></p>
  <% if !@failures.empty? %>
    <p><%= t(:failures, <<-TEXT)
      There were some files we didn't know what to do with. They have not been
      added to anyone's submission page. You can see the list to the left.
      TEXT
    %></p>
  <% end %>
  <a href="<%= context_url(@context, :context_assignment_url, @assignment.id) %>" class="btn button-sidebar-wide">
    {{> icons/arrow-left}}
    {{#t}}Back to Assignment Page{{/t}}
  </a>
  <a href="<%= context_url(@context, :context_gradebook_url) %>" class="btn button-sidebar-wide">
    {{> icons/arrow-left}}
    {{#t}}Back to Gradebook{{/t}}
  </a>
<% end %>

<% content_for :stylesheets do %>
<style>
#student_list {
  list-style-type: none;
  margin: 0 0 20px;
  font-size: 1.5em;
  padding-left: 10px;
}
#student_list li {
  padding: 2px 25px;
  background-image: url(/images/person.png);
  background-repeat: no-repeat;
  background-position: 3px 10px;
}
#student_list .file_list {
  list-style-type: none;
  padding-left: 5px;
  font-size: 0.8em;
  margin-bottom: 5px;
}
#student_list .file_list li {
  background-image: url(/images/file.png);
  background-position: 3px 6px;
}
#failure_list {
  list-style-type: none;
  margin: 0;
  padding-left: 10px;
}
#failure_list li {
  padding: 3px 25px;
  background-image: url(/images/file.png);
  background-repeat: no-repeat;
  background-position: 3px 6px;
}
</style>
<% end %>

<h2><%= t(:submissions_upload, "%{assignment} Submissions Upload", :assignment => @assignment.title) %></h2>
<h3 style="margin-top: 5px;">{{#t}}Attached files to the following user submissions{{/t}}</h3>
<ul id="student_list" style="margin-top: 10px;">
<% if @comments.empty? %>
  <li>{{#t}}No Comments Added{{/t}}</li>
<% end %>
<% @comments.flatten.each do |comment| %>
  <li>
    <a href="<%= context_url(@context, :context_assignment_submission_url, @assignment.id, comment.submission.user_id) %>"><%= comment.submission.user.name %></a>
    <ul class="file_list">
      <% comment.attachments.each do |file| %>
      <li>
        <a href="<%= context_url(@context, :context_assignment_submission_url, @assignment.id, comment.submission.user_id, :download => file.id, :comment_id => comment.id) %>"><%= file.display_name %></a>
        <% if file.filename != file.display_name %>
          <span style="font-size: 0.6em;">(<%= t(:renamed_file, "renamed from %{filename}", :filename => file.filename) %>)</span>
        <% end %>
      </li>
      <% end %>
    </ul>
  </li>
<% end %>
</ul>
<% unless @failures.empty? %>
  <h3 style="margin-top: 40px;">{{#t}}Ignored the following files{{/t}}</h3>
  <ul id="failure_list">
  <% @failures.each do |failure| %>
    <li><%= failure.match(/\/([^\/]*)\z/)[1].to_s %></li>
  <% end %>
  </ul>
<% end %>
